package com.gdc.cloud.controller;

import com.gdc.cloud.entities.CommonResult;
import com.gdc.cloud.entities.Payment;
import com.gdc.cloud.service.PaymentFeignService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * Description: 订单消费者模块启动类
 * @author: gdc
 * @date: 2021/1/31
 * @version 1.0
 */
@RestController
@Slf4j
public class OrderController {

    @Resource
    private PaymentFeignService paymentFeignService;

    /**
     * 创建 支付信息
     * @param payment               支付信息
     * @return                      结果
     */
    @GetMapping("/consumer/payment/create")
    public CommonResult<Payment> create(Payment payment){
        return paymentFeignService.create(payment);
    }

    /**
     * 通过ID获取支付信息
     * @param id                    ID
     * @return                      支付信息
     */
    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        return paymentFeignService.getPayment(id);
    }

    /**
     * 测试 OpenFeign 的超时控制功能, openfeign-ribbon 客户端默认等待1s
     * @return                      结果
     */
    @GetMapping(value = "/consumer/payment/feign/timeout")
    public String paymentFeignTimeout() {
        return paymentFeignService.paymentFeignTimeout();
    }

}
